const {db} = require('../util/util')

const nfts = () => {
    sql = 'SELECT * FROM nft WHERE complete = 1'
    return db.execute(sql)
}

const uncompleteNft = () => {
    sql = 'SELECT * FROM nft WHERE complete = 0'
    return db.execute(sql)
}

const nft = (id) => {
    sql = 'SELECT * FROM nft WHERE _id = ?'
    return db.execute(sql, [id])
}

const createNft = () => {
    sql = 'INSERT INTO nft (createAt) VALUES (?)'
    return db.execute(sql, [Date.now()])
}

const updateNftCount = (count, id) => {
    sql = 'UPDATE nft SET count = ? WHERE _id = ?'
    return db.execute(sql, [count, id])
}

const updateNftComplete = (id) => {
    sql = 'UPDATE nft SET complete = 1 WHERE _id = ?'
    return db.execute(sql, [id])
}

const updateNft = (nft) => {
    sql = 'UPDATE nft SET name = ?, description = ?, img = ?, owner = ?, transferFrom = ?, transferTo = ?, createAt = ?, updateAt = ?, complete = ?, count = ? WHERE _id = ?'
    return db.execute(sql, [nft.name, nft.description, nft.img, nft.owner, nft.transferFrom, nft.transferTo, nft.createAt, Date.now(), nft.complete, nft.count, nft._id])
}
module.exports = {uncompleteNft, createNft, updateNftComplete, updateNftCount, nft, updateNft, nfts}